package com.example.springboottestgit.service.instruction.stage1;

import com.example.springboottestgit.bean.InstructData;
import com.example.springboottestgit.common.RunNum;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @description: 退还保证金
 * @author: ZZZ
 */
@Service
public class tenderBackMargin {
    static int failTender = 0;
    static int winTender = 0;
    static int withdrawTender = 0;

    public List<InstructData> getInstructData() {
        List<InstructData> list = new ArrayList<>();
        for (int i = 1; i <= RunNum.a; i++) {
            //未中标退还保证金
            list.add(failTenderBackMargin(i % 2 == 0));
            //中标退还保证金
            list.add(winTenderBackMargin(i % 2 == 0));
            //撤标退还保证金
            list.add(withdrawTenderBackMargin(i % 2 == 0));
        }
        return list;
    }

    public InstructData failTenderBackMargin(Boolean b) {
        Random random = new Random();
        //Boolean b = random.nextBoolean();
        int x = 5;
        if (b == true) {
            //x = random.nextInt(40) + 1;
            failTender++;
            x = failTender;
            if (failTender == 30) {
                failTender = 0;
            }
        }
        String sign = x == 5 ? "符合" : "不符合";
        String e = x == 5 ? "等于" : "不等于";

        String instruction = "未中标人的投标保证金将在中标通知书发出之日起x个工作日内退回原账户是否符合法律法规";
        String input = "";
        String output = "#。根据《中华人民共和国政府采购法实施条例》第三十三条规定，采购人或者采购代理机构应当自中标通知书发出之日起5个工作日内退还未中标供应商的投标保证金，因此案例中未中标人的投标保证金将在中标通知书发出之日起x个工作日内退回原账户#法律法规。";

        instruction = instruction.replace("x", x + "");
        output = output.replace("x", x + "").replace("#", sign + "").replace("e", e + "");

        InstructData instructData = new InstructData();
        instructData.setInstruction(instruction);
        instructData.setInput("");
        instructData.setOutput(output);
        return instructData;
    }

    public InstructData winTenderBackMargin(Boolean b) {
        Random random = new Random();
        //Boolean b = random.nextBoolean();
        int x = 5;
        if (b == true) {
            //x = random.nextInt(40) + 1;
            winTender++;
            x = winTender;
            if (winTender == 30) {
                winTender = 0;
            }
        }
        String sign = x == 5 ? "符合" : "不符合";
        String e = x == 5 ? "等于" : "不等于";

        String instruction = "中标人的投标保证金将在政府采购合同签订之日起x个工作日内退回原账户是否符合法律法规";
        String input = "";
        String output = "#。根据《中华人民共和国政府采购法实施条例》第三十三条规定，采购人或者采购代理机构应当自政府采购合同签订之日起5个工作日内退还中标供应商的投标保证金，因此案例中中标人的投标保证金将在政府采购合同签订之日起x个工作日内退回原账户#法律法规。";

        instruction = instruction.replace("x", x + "");
        output = output.replace("x", x + "").replace("#", sign + "").replace("e", e + "");

        InstructData instructData = new InstructData();
        instructData.setInstruction(instruction);
        instructData.setInput("");
        instructData.setOutput(output);
        return instructData;
    }

    public InstructData withdrawTenderBackMargin(Boolean b) {
        Random random = new Random();
        //Boolean b = random.nextBoolean();
        int x = 5;
        if (b == true) {
            //x = random.nextInt(40) + 1;
            withdrawTender++;
            x = withdrawTender;
            if (withdrawTender == 30) {
                withdrawTender = 0;
            }
        }
        String sign = x == 5 ? "符合" : "不符合";
        String e = x == 5 ? "等于" : "不等于";

        String instruction = "在投标截止时间前撤回投标文件的投标人，其投标保证金将在招标人收到投标人书面撤回通知之日起x个工作日内退回原账户是否符合法律法规";
        String input = "";
        String output = "#。根据《中华人民共和国招标投标法实施条例》第三十五条规定，投标人撤回已提交的投标文件，应当在投标截止时间前书面通知招标人。招标人已收取投标保证金的，应当自收到投标人书面撤回通知之日起5日内退还。";

        instruction = instruction.replace("x", x + "");
        output = output.replace("x", x + "").replace("#", sign + "").replace("e", e + "");

        InstructData instructData = new InstructData();
        instructData.setInstruction(instruction);
        instructData.setInput("");
        instructData.setOutput(output);
        return instructData;
    }
}
